Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Plugins / Purple Service / adiumPurpleCore.m
blob23d0db100c23785efcd2ca6b77e621477f2cf433
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "adiumPurpleCore.h"
19 #import "adiumPurpleAccounts.h"
20 #import "adiumPurpleBlist.h"
21 #import "adiumPurpleConnection.h"
22 #import "adiumPurpleConversation.h"
23 #import "adiumPurpleDnsRequest.h"
24 #import "adiumPurpleEventloop.h"
25 #import "adiumPurpleFt.h"
26 #import "adiumPurpleNotify.h"
27 #import "adiumPurplePrivacy.h"
28 #import "adiumPurpleRequest.h"
29 #import "adiumPurpleRoomlist.h"
30 #import "adiumPurpleSignals.h"
31 #import "adiumPurpleWebcam.h"
32 #import "adiumPurpleCertificateTrustWarning.h"
34 #import <AdiumLibpurple/SLPurpleCocoaAdapter.h>
35 #import "AILibpurplePlugin.h"
36 #import <AIUtilities/AIFileManagerAdditions.h>
38 #pragma mark Debug
39 // Debug ------------------------------------------------------------------------------------------------------
40 #if (PURPLE_DEBUG)
41 static void adiumPurpleDebugPrint(PurpleDebugLevel level, const char *category, const char *debug_msg)
43         //Log error
44         if (!category) category = "general"; //Category can be nil
45         AILog(@"(Libpurple: %s) %s",category, debug_msg);
48 static PurpleDebugUiOps adiumPurpleDebugOps = {
49     adiumPurpleDebugPrint
52 PurpleDebugUiOps *adium_purple_debug_get_ui_ops(void)
54         return &adiumPurpleDebugOps;
56 #endif
58 // Core ------------------------------------------------------------------------------------------------------
60 extern gboolean purple_init_ssl_plugin(void);
61 extern gboolean purple_init_ssl_openssl_plugin(void);
62 extern gboolean purple_init_ssl_cdsa_plugin(void);
64 static void init_all_plugins()
66         AILog(@"adiumPurpleCore: load_all_plugins()");
68         //First, initialize our built-in plugins
69         purple_init_ssl_plugin();
70 #ifdef HAVE_CDSA
71         purple_init_ssl_cdsa_plugin();
72 #else
73         #ifdef HAVE_OPENSSL
74                 purple_init_ssl_openssl_plugin();
75         #else
76                 #warning No SSL plugin!
77         #endif
78 #endif
80         //Load each plugin
81         NSEnumerator                    *enumerator = [[SLPurpleCocoaAdapter libpurplePluginArray] objectEnumerator];
82         id <AILibpurplePlugin>  plugin;
84         while ((plugin = [enumerator nextObject])) {
85                 if ([plugin respondsToSelector:@selector(installLibpurplePlugin)]) {
86                         [plugin installLibpurplePlugin];
87                 }
88         }
89 #ifdef HAVE_CDSA
90         {
91                 PurplePlugin *cdsa_plugin = purple_plugins_find_with_name("CDSA");
92                 if(cdsa_plugin) {
93                         gboolean ok = NO;
94                         purple_plugin_ipc_call(cdsa_plugin, "register_certificate_ui_cb", &ok, adium_query_cert_chain);
95                 }
96         }
97 #endif
100 static void load_external_plugins(void)
102         //Load each plugin
103         NSEnumerator                    *enumerator = [[SLPurpleCocoaAdapter libpurplePluginArray] objectEnumerator];
104         id <AILibpurplePlugin>  plugin;
105         
106         while ((plugin = [enumerator nextObject])) {
107                 if ([plugin respondsToSelector:@selector(loadLibpurplePlugin)]) {
108                         [plugin loadLibpurplePlugin];
109                 }
110         }       
113 static void adiumPurplePrefsInit(void)
115     //Disable purple away handling - we do it ourselves
116         purple_prefs_set_bool("/purple/away/away_when_idle", FALSE);
117         purple_prefs_set_string("/purple/away/auto_reply","never");
119         //Disable purple idle reporting - we do it ourselves
120         purple_prefs_set_bool("/purple/away/report_idle", FALSE);
122     //Disable purple conversation logging
123     purple_prefs_set_bool("/purple/logging/log_chats", FALSE);
124     purple_prefs_set_bool("/purple/logging/log_ims", FALSE);
126     //Typing preference
127     purple_prefs_set_bool("/purple/conversations/im/send_typing", TRUE);
128         
129         //Use server alias where possible
130         purple_prefs_set_bool("/purple/buddies/use_server_alias", TRUE);
132         //Ensure we are using caching
133         purple_buddy_icons_set_caching(TRUE);   
136 static void adiumPurpleCoreDebugInit(void)
138 #if (PURPLE_DEBUG)
139         AILog(@"adiumPurpleCoreDebugInit()");
140     purple_debug_set_ui_ops(adium_purple_debug_get_ui_ops());
141 #endif
142         
143         //Initialize all external plugins.
144         init_all_plugins();
147 /* The core is ready... finish configuring libpurple and its plugins */
148 static void adiumPurpleCoreUiInit(void)
149 {               
150         bindtextdomain("pidgin", [[[NSBundle bundleWithIdentifier:@"im.pidgin.libpurple"] resourcePath] UTF8String]);
151         bind_textdomain_codeset("pidgin", "UTF-8");
152         textdomain("pidgin");
153         
154         const char *preferredLocale = [[[[NSBundle bundleForClass:[SLPurpleCocoaAdapter class]] preferredLocalizations] objectAtIndex:0] UTF8String];
155         //We should be able to just do setlocale()... but it always returns NULL, which indicates failure
156         /* setlocale(LC_MESSAGES, preferredLocale); */
158         //So we'll set the environment variable for this process, which does work
159         setenv("LC_ALL", preferredLocale, /* overwrite? */ 1);
160         setenv("LC_MESSAGES", preferredLocale, /* overwrite? */ 1);
162         AILog(@"adiumPurpleCoreUiInit");
163         //Initialize the core UI ops
164     purple_blist_set_ui_ops(adium_purple_blist_get_ui_ops());
165     purple_connections_set_ui_ops(adium_purple_connection_get_ui_ops());
166     purple_privacy_set_ui_ops (adium_purple_privacy_get_ui_ops());      
167         purple_accounts_set_ui_ops(adium_purple_accounts_get_ui_ops());
169         /* Why use Purple's accounts and blist list when we have the information locally?
170                 *               - Faster account connection: Purple doesn't have to recreate the local list
171                 *               - Privacy/blocking support depends on the accounts and blist files existing
172                 *
173                 *       Another possible advantage:
174                 *               - Using Purple's own buddy icon caching (which depends on both files) allows us to avoid
175                 *                       re-requesting icons we already have locally on some protocols such as AIM.
176                 */      
177         //Setup the buddy list; then load the blist.
178         purple_set_blist(purple_blist_new());
179         AILog(@"adiumPurpleCore: purple_blist_load()...");
180         purple_blist_load();
181         
182         //Configure signals for receiving purple events
183         configureAdiumPurpleSignals();
184         
185         //Configure the GUI-related UI ops last
186         purple_roomlist_set_ui_ops (adium_purple_roomlist_get_ui_ops());
187     purple_notify_set_ui_ops(adium_purple_notify_get_ui_ops());
188     purple_request_set_ui_ops(adium_purple_request_get_ui_ops());
189         purple_xfers_set_ui_ops(adium_purple_xfers_get_ui_ops());
190         purple_dnsquery_set_ui_ops(adium_purple_dns_request_get_ui_ops());
191         
192         adiumPurpleConversation_init();
194 #if     ENABLE_WEBCAM
195         initPurpleWebcamSupport();
196 #endif
197         
198         load_external_plugins();
201 static void adiumPurpleCoreQuit(void)
203     AILog(@"Core quit");
204     exit(0);
207 static PurpleCoreUiOps adiumPurpleCoreOps = {
208     adiumPurplePrefsInit,
209     adiumPurpleCoreDebugInit,
210     adiumPurpleCoreUiInit,
211     adiumPurpleCoreQuit
214 PurpleCoreUiOps *adium_purple_core_get_ops(void)
216         return &adiumPurpleCoreOps;